package com.cash.app.ui.order

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.cash.app.base.BaseViewModel
import com.cash.app.constant.AppConstant.TYPE_LOAN_LIST_ALL
import com.cash.app.manager.api.GlobalAPIService
import com.cash.app.manager.model.LoanDataResponse
import com.cash.app.manager.model.LoanListRequest
import com.cash.app.net.NetRequestExecutor
import com.cash.app.net.RetrofitClient

class LoanListViewModel : BaseViewModel() {

    private val apiService = RetrofitClient.createService(GlobalAPIService::class.java)

    private val _loanData = MutableLiveData<LoanDataResponse>()
    val loanData: LiveData<LoanDataResponse> = _loanData

    private val _showEmptyState = MutableLiveData<Boolean>()
    val showEmptyState: LiveData<Boolean> = _showEmptyState

    fun getLoanList() {
        launchRequest(
            request = {
                NetRequestExecutor.baseNetRequest {
                    apiService.getLoanList(
                        LoanListRequest(
                            list_type = TYPE_LOAN_LIST_ALL
                        )
                    )
                }
            },
            onSuccess = { response ->
                response?.let {
                    if (response.order_list.isEmpty()) {
                        _showEmptyState.value = true
                    } else {
                        _showEmptyState.value = false
                        _loanData.value = response!!
                    }
                }
            }
        )
    }
} 